package com.example.sunmiv1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.VipListBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class VipInfoAdapter extends BaseAdapter {
    private Context context;
    private List<VipListBean.InfoBean> vipInfoList;

    public VipInfoAdapter(Context context, List<VipListBean.InfoBean> vipInfoList) {
        this.context = context;
        this.vipInfoList = vipInfoList;
    }

    @Override
    public int getCount() {
        return vipInfoList.size();
    }

    @Override
    public Object getItem(int i) {
        return vipInfoList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_vip_info, null);
            vh = new ViewHolder(view);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        if (vipInfoList.get(i).getNickname() != null && !"".equals(vipInfoList.get(i).getNickname())) {
            vh.tvVipName.setText(vipInfoList.get(i).getNickname());
        } else {
            vh.tvVipName.setText(vipInfoList.get(i).getName());
        }
        vh.tvVipPhone.setText(vipInfoList.get(i).getCardnum());

        return view;
    }

    static class ViewHolder {
        @BindView(R.id.tv_vip_name)
        TextView tvVipName;
        @BindView(R.id.tv_vip_phone)
        TextView tvVipPhone;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
